#!/usr/bin/python
# -*- coding:utf-8 -*-

"""
@file: example.py
@time: 2023/10/01 10:00:00
@author: cf
@version: 1.0
@description: 这是一个示例Python脚本，用于演示如何编写注释。
"""

# 导入必要的模块
import os
import sys
import math
from decimal import Decimal
from Compute import OtherParameters

from WellTrajectoryData import WellTrajectoryData
def main():
    # paragraph = 60.08 - 32.87
    # curv1 = 0.27 * math.pi / 180
    # curv2 = 0.45 * math.pi / 180
    # derection_cur1 = 160.26 * math.pi / 180
    # derection_cur2 = 205.66 * math.pi / 180
    # ε = math.cos(curv2 - curv1) - math.sin(curv2) * math.sin(curv1) * (1 - math.cos(derection_cur2 - derection_cur1))
    # min_curvature = calculate_min_curvature(math.acos(ε))
    # vertical_depth = 32.87 + paragraph / 2 * (
    #             math.cos(curv1) + math.cos(curv2)) * min_curvature
    # ns_coordinates = (-0.07) + paragraph / 2 * (math.sin(curv1) * math.cos(derection_cur1)+math.sin(curv2) * math.cos(derection_cur2))*min_curvature
    # ew_coordinates = (0.03) + paragraph / 2 * (math.sin(curv1) * math.sin(derection_cur1)+math.sin(curv2) * math.sin(derection_cur2))*min_curvature
    # print(vertical_depth)
    # print(ns_coordinates)
    # print(ew_coordinates)
    # 创建 previous_data 和 current_data 实例
    # previous_data = WellTrajectoryData(
    #     well_depth=32.87,
    #     well_slope=0.27,
    #     azimuth=160.26,
    #     vertical_depth=32.8698783449238,
    #     ns_coordinates=-0.0728967379752004,
    #     ew_coordinates=0.026158241211035,
    #     closed_orientation=160.26,
    #     closed_displacement=0.0774479695710592,
    #     eye_displacement=0.0685467883872609,
    #     dogleg_degree=0.246425311834522,
    #     ordinate=3246136.90710326,
    #     abscissa=18550536.4461582
    # )
    #
    # current_data = WellTrajectoryData(
    #     well_depth=60.08,
    #     well_slope=0.45,
    #     azimuth=205.66
    # )
    # previous_data = WellTrajectoryData(
    #     well_depth=87.61,
    #     well_slope=0.53,
    #     azimuth=281.06,
    #     vertical_depth=87.61,
    #     ns_coordinates=-0.30,
    #     ew_coordinates=-0.17,
    #     closed_orientation=209.36,
    #     closed_displacement=0.35,
    #     eye_displacement=0.32,
    #     dogleg_degree=0.66,
    #     ordinate=3246136.68,
    #     abscissa=18550536.25
    # )
    # current_data = WellTrajectoryData(
    #     well_depth=114.62,
    #     well_slope=0.26,
    #     azimuth=95.06
    # )

    cur_data = WellTrajectoryData(
        well_depth=Decimal('60.08'),
        well_slope=Decimal('0.45'),
        azimuth=Decimal('205.66'),
    )
    prev_trajectory_data = WellTrajectoryData(
        well_depth=Decimal('32.87'),
        well_slope=Decimal('0.27'),
        azimuth=Decimal('160.26'),
        vertical_depth=Decimal('32.8698783449238'),
        ns_coordinates=Decimal('-0.0728967379752004'),
        ew_coordinates=Decimal('0.026158241211035'),
        closed_orientation=Decimal('160.26'),
        closed_displacement=Decimal('0.0774479695710592'),
        eye_displacement=Decimal('0.0685467883872609'),
        dogleg_degree=Decimal('0.246425311834522'),
        abscissa=Decimal('18550536.4461582'),
        ordinate=Decimal('3246136.68')
    )
    o= OtherParameters()
    a= o.calculate_other_parameters([prev_trajectory_data, cur_data])
    print(a)





# def calculate_min_curvature(epsilon):
#     try:
#         # 当 epsilon 不为 0 时，正常计算
#         if epsilon != 0:
#             result = 2 / epsilon * math.tan(epsilon / 2)
#             return result
#         else:
#             # 当 epsilon 为 0 时，根据极限值返回 1
#             return 1
#     except Exception as e:
#         # 捕获其他可能的异常，例如 math 域错误等
#         print(f"Error in calculation: {e}")
#         return 1  # 返回默认值 1

if __name__ == "__main__":
    main()





# class ComputeTrajectoryData:
#     def computeTrajectoryData (self,designOrientation,ordinate1,abscissa1,lostData,wellDepth,wellSlope,azimuth):
#         self.trajectoryData.wellDepth = wellDepth
#         self.trajectoryData.wellSlope = wellSlope
#         self.trajectoryData.azimuth = azimuth
#         longNum = wellDepth-lostData[0] if self.trajectoryData.wellDepth > 0 else 0
#         wellSlopeRadian = math.radians(wellSlope)
#         azimuthRadian = math.radians(azimuth)
#         ε = math.cos(wellSlopeRadian - math.radians(lostData[1])) - math.sin(wellSlopeRadian) * math.sin(math.radians(lostData[1]) * (1 - math.cos(azimuthRadian - math.radians(lostData[2]))))
#         εRadian = math.acos(ε)
#         minimumCurvature = (2 / εRadian) * math.tan(εRadian / 2)
#         self.trajectoryData.verticalDepth = (lostData[3] + longNum / 2 * (math.cos(math.radians(lostData[1]))+math.cos(math.radians(wellSlope))) * minimumCurvature) if self.trajectoryData.wellDepth > 0 else 0
#         self.trajectoryData.nsCoordinates = (lostData[4] + longNum / 2 * (math.sin(math.radians(lostData[1])) * math.cos(math.radians(lostData[2])) + math.sin(wellSlopeRadian) * math.cos(azimuthRadian)) * minimumCurvature) if self.trajectoryData.wellDepth > 0 else 0
#         self.trajectoryData.ewCoordinates = (lostData[5] + longNum / 2 * (math.sin(math.radians(lostData[1])) * math.sin(math.radians(lostData[2])) + math.sin(wellSlopeRadian) * math.sin(azimuthRadian)) * minimumCurvature) if self.trajectoryData.wellDepth > 0 else 0
#         θ1 = abs(math.atan(self.trajectoryData.ewCoordinates / self.trajectoryData.nsCoordinates)) if wellDepth > 0 and self.trajectoryData.ewCoordinates != 0 else (math.pi / 2 if wellDepth > 0 else "")
#         θ = θ1 if 0 < self.trajectoryData.ewCoordinates and self.trajectoryData.nsCoordinates > 0 else (math.pi - θ1 if 0 < self.trajectoryData.ewCoordinates and self.trajectoryData.nsCoordinates < 0 else (math.pi + θ1 if 0 > self.trajectoryData.ewCoordinates and self.trajectoryData.nsCoordinates < 0 else 2 * math.pi - θ1))
#         self.trajectoryData.closedOrientation = θ / math.pi * 180 if not isinstance(θ, (str, bool)) and θ != 0 else ""
#         self.trajectoryData.closedDisplacement =  math.sqrt(self.trajectoryData.nsCoordinates ** 2 + self.trajectoryData.ewCoordinates ** 2) if wellDepth > 0 else ""
#         self.trajectoryData.eyeDisplacement =  math.cos(designOrientation * math.pi / 180 - θ) * math.sqrt(self.trajectoryData.nsCoordinates ** 2 + self.trajectoryData.ewCoordinates ** 2) if wellDepth > 0 else ""
#         self.trajectoryData.doglegDegree =  εRadian * 180 / math.pi * 30 / longNum if wellDepth > 0 and longNum != 0 else ""
#         self.trajectoryData.ordinate =  ordinate1 + self.trajectoryData.nsCoordinates if wellDepth > 0 else ""
#         self.trajectoryData.abscissa =  abscissa1 + self.trajectoryData.ewCoordinates if wellDepth > 0 else ""
#         return self.trajectoryData
